package com.myWeb.controller;

import com.myWeb.dao.QuestionDao;
import com.myWeb.entity.Question;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class QuestionUpdateServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String title,questionA, questionB,questionC,questionD,answer;
        Integer questionId = Integer.valueOf(request.getParameter("questionId"));
        title = request.getParameter("title");
        questionA = request.getParameter("questionA");
        questionB = request.getParameter("questionB");
        questionC = request.getParameter("questionC");
        questionD = request.getParameter("questionD");
        answer = request.getParameter("answer");
        Question question = new Question(questionId,title,questionA,questionB,questionC,questionD,answer);
        QuestionDao dao = new QuestionDao();
        int result = dao.update(question,request);
        if(result == 1){
            request.setAttribute("info","试题更新成功");
        }else{
            request.setAttribute("info","试题更新失败");
        }
        request.getRequestDispatcher("/info.jsp").forward(request,response);
    }
}
